<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片轮播</title>
</head>
<body>
    <img src="../img/1.jpg" alt="">
</body>
<script>
    //获取img图片标签元素
    let img = document.images[0]
    //变量控制图片轮播的切换
    let i = 2

    //改变图片的函数
    function changeImg(){
        if(i<=5){
            img.src=`../img/${i}.jpg`
            i++
        }
        if(i>5){
            i = 1
        }
    }

    //设置定时器，每隔一秒刷新图片
    let t = window.setInterval(changeImg,1000)

    //鼠标悬浮  停止轮播
    img.onmouseover = function(){
        window.clearInterval(t)
    }

    //鼠标离开  继续轮播
    img.onmouseout = function(){
        t = window.setInterval(changeImg,1000)
    }
</script>
</html>